
    $("#z-command").click(function(event) {
	        if($(this).hasClass('color040')){
	            $(this).addClass('color929').removeClass('color040');
	        }else{
	            $(this).removeClass('color929').addClass('color040');
	        }
	 });

    $(".remember_login").click(function(event) {
        if($(this).hasClass('color040')){
            $(this).addClass('color929').removeClass('color040');
        }else{
            $(this).removeClass('color929').addClass('color040');
        }
    });
    
    $("#scanning-code").click(function(event) {
        if($(this).hasClass('color040')){
            $(this).addClass('color929').removeClass('color040');
        }else{
            $(this).removeClass('color929').addClass('color040');
        }
    });
    
    
    

/***************************短信验证码****************************/
var clock;
var nums = 60;


function regSendSms(e){
	
	if(!$(e).hasClass("disabled")){
		var phonenum = $("#phonenum").val();
		var data_url = $(e).attr('data_url');
		if(!phonenum){
			$("#phonenum").focus();
			updateAlert("手机号码还没有填写哦","alert-error");
			return false;
		}
		
		if(phonenum.length != '11'){
			$("#phonenum").focus();
			updateAlert("手机号格式不正确","alert-error");
			return false;
		}
		
		if(!/^1[345678]\d{9}$/.test(phonenum)){
			$("#phonenum").focus();
			updateAlert("手机号格式不正确","alert-error");
			return false;
		}
		
		//是否有图片验证码
		var img_verify_code = "";
		if(!$("#img_register_verify").hasClass('hidden')){
			img_verify_code = $("#z-img-code").val();
			if(!img_verify_code){
				$("#z-img-code").focus();
				updateAlert("图片验证码还没填写哦","alert-error");
				return false;
			}
		}
		var is_login = $(e).attr("is_login");
		var get_code_btn = $('#z-code-time');
		$.ajax({ 
			dataType:'json',
            url: data_url, 
            data: {phonenum:phonenum,img_verify_code:img_verify_code,is_login:is_login},
            success: function(obj){
               if(obj.status == 1){
                   clock = setInterval(doRegisterLoop, 1000);
                   get_code_btn.css({"border":"1px solid #929292","color":"#929292","cursor":"default"});
                   get_code_btn.addClass("disabled");
                   get_code_btn.html(nums + "s");
               }else if(obj.status == 2){
            	   $("#img_register_verify").removeClass('hidden');
            	   updateAlert(obj.info,"alert-error");
            	   $(".modify-block").css("height","467px");
            	   $("#binding-phone").css("height","660px");
            	   $("#z-img-code").focus();
               }else{
            	    get_code_btn.css({"border":"1px solid #01b040","color":"#01b040"});
            	    
            	    var code = $("#z-message-code").val();
            	    
                    if(obj.info=="该手机号码已经被绑定" || (obj.info=="图片验证码错误" && !code)){
            	    	get_code_btn.html("获取短信验证码");
            	    }else{
            	    	get_code_btn.html("重新获取");
            	    }
                    
                    if(obj.info == '图片验证码错误'){
             		   var ref_img_data_url = $('#z-refresh-code').attr('data-url');
                   	   $(".reg-img-code img").attr('src',ref_img_data_url+'&t='+Math.random());
             	    }
                    
                    get_code_btn.removeClass("disabled");
                    nums = 60;
                    updateAlert(obj.info,"alert-error");
               }
            }
        });
		
		
	}
};


function doRegisterLoop() {
	var get_code_btn = $('#z-code-time');
    nums--;
    if (nums > 0) {
    	get_code_btn.html(nums + "s");
    } else {
        clearInterval(clock);
        get_code_btn.css({"border":"1px solid #01b040","color":"#01b040","cursor":"pointer"});
        get_code_btn.html("重新获取");
        get_code_btn.removeClass("disabled");
        nums = 60;
    }
}


function register(even){
	var phonenum = $("#phonenum").val();
	var pwd = $("#z-passward").val();
	var code = $("#z-message-code").val();
	var register_type = $("#register_type").val();
	var back_url = $("#back_url").val();
	var ziwork_hash = $("meta[name='__ziwork_hash__']").attr('content');
	
	var passwardLength = pwd.length;
	
	var go = $(even).attr("go");
	if(go == "0"){
		updateAlert("正在注册中","alert-error");
		return false;
	}
	
	
	if(!phonenum){
		$("#phonenum").focus();
		updateAlert("手机号码还没有填写哦","alert-error");
		return false;
	}
	
	if(phonenum.length != '11'){
		$("#phonenum").focus();
		updateAlert("手机号格式不正确","alert-error");
		return false;
	}
	
	if(!/^1[345678]\d{9}$/.test(phonenum)){
		$("#phonenum").focus();
		updateAlert("手机号格式不正确","alert-error");
		return false;
	}
	
	
	
	
	//密码必须由数字，字母，特殊字符中的两种以上组成--var passNum= !!passward.match(/(?=.*[a-z])(?=.*\d)(?=.*[#@!~%^&*])[a-z\d#@!~%^&*]{6,20}/i);
    var passNum= !!pwd.match(/^\S+$/gi);

    if(!pwd || pwd == ""){
		updateAlert("密码必须填写~","alert-error");
		return false;
	}else if(passNum == false){
    	updateAlert("密码不能有空格","alert-error");
        return false;
    }else if(passwardLength<6){
    	updateAlert("密码长度不能小于6位","alert-error");
        return false;
    }else if(passwardLength>20){
    	updateAlert("密码长度不能大于20位","alert-error");
        return false;
    }
	
	
	if(!code || code == ""){
		$("#z-message-code").focus();
		updateAlert("验证码不能为空哦","alert-error");
		return false;
	}
	
	var command = 1;
	if($("#z-command").hasClass('color929')){
		updateAlert("请勾选自客使用条约与协议","alert-error");
		command = 0;
        return false;
    }
	
	if(register_type != "home" && register_type != "profile"){
		updateAlert("提交异常，请刷新页面再试试","alert-error");
		return false;
	}
	
	
	var data_url = $(even).attr('data-url');
	$(even).html("注册中...");
	$(even).attr("go",0);
	$.ajax({ 
		dataType:'json',
        url: data_url, 
        type:"post",
        data: {back_url:back_url,phonenum:phonenum,pwd:pwd,code:code,register_type:register_type,command:command,__ziwork_hash__:ziwork_hash},
        success: function(obj){
        	
        	var btn_html = register_type == "home" ? "开启自由职业人生" : "马上招人";
        	$(even).html(btn_html);
        	$(even).attr("go",1);
        	
           if(obj.status == 1){
        	   updateAlert("注册成功","alert-success");
        	   setInterval(function(){
        		   window.location.href = obj.info;
        	   }, 2000);
           }else {
        	   updateAlert(obj.info,"alert-error");
        	   
        	   /*if(obj.info == '请重新获取验证码'){
        		   var ref_img_data_url = $('#z-refresh-code').attr('data-url');
              	   $(".reg-img-code img").attr('src',ref_img_data_url+'&t='+Math.random());
        	   }*/
        	  
               return false;
           }
        }
    });
	
	
}

$("#login-password-btn").click(function(){
	var phonenum = $("input[name='phonenum']").val();
	var password = $("input[name='password']").val();
	var back_url = $("#back_url").val();
	var ziwork_hash = $("meta[name='__ziwork_hash__']").attr('content');
	
	var passwardLength = password.length;
	
	var even = $(this);
	
	var go = even.attr("go");
	if(go == "0"){
		updateAlert("正在登录中","alert-error");
		return false;
	}
	
	
	if(!phonenum){
		$("input[name='phonenum']").focus();
		updateAlert("手机号码还没有填写哦","alert-error");
		return false;
	}else if(phonenum.length != '11'){
		$("input[name='phonenum']").focus();
		updateAlert("手机号格式不正确","alert-error");
		return false;
	}else if(!/^1[345678]\d{9}$/.test(phonenum)){
		$("input[name='phonenum']").focus();
		updateAlert("手机号格式不正确","alert-error");
		return false;
	}
	
	//密码必须由数字，字母，特殊字符中的两种以上组成--var passNum= !!passward.match(/(?=.*[a-z])(?=.*\d)(?=.*[#@!~%^&*])[a-z\d#@!~%^&*]{6,20}/i);
    var passNum= !!password.match(/^\S+$/gi);

    if(!password || password == ""){
		updateAlert("密码必须填写~","alert-error");
		return false;
	}else if(passNum == false){
    	updateAlert("密码不能有空格","alert-error");
        return false;
    }else if(passwardLength<6){
    	updateAlert("密码长度不能小于6位","alert-error");
        return false;
    }else if(passwardLength>20){
    	updateAlert("密码长度不能大于20位","alert-error");
        return false;
    }
	
    var remember = 1;
	if($("#password-login .remember_login").hasClass('color929')){
		remember = 0;
        //return false;
    }
    
	var data_url = even.attr('data-url');
	even.html("登录中...");
	even.attr("go",0);
	$.ajax({ 
		dataType:'json',
        url: data_url, 
        type:"post",
        data: {back_url:back_url,phonenum:phonenum,password:password,remember:remember,__ziwork_hash__:ziwork_hash,login_type:"password"},
        success: function(obj){
        	
        	even.html("登录自客");
        	even.attr("go",1);
        	
           if(obj.status == 1){
        	   updateAlert("登录成功","alert-success");
        	   setInterval(function(){
        		   window.location.href = obj.info;
        	   }, 2000);
           }else {
        	   updateAlert(obj.info,"alert-error");
        	   if(obj.token){
        		   $("meta[name='__ziwork_hash__']").attr('content',obj.token);
               }
               return false;
           }
        }
    });
	
});

$("#login-sms-btn").click(function(){
	var phonenum = $("#phonenum").val();
	var code = $("#z-message-code").val();
	var back_url = $("#back_url").val();
	var ziwork_hash = $("meta[name='__ziwork_hash__']").attr('content');
	
	var even = $(this);
	
	var go = even.attr("go");
	if(go == "0"){
		updateAlert("正在登录中","alert-error");
		return false;
	}
	
	
	if(!phonenum){
		$("input[name='phonenum']").focus();
		updateAlert("手机号码还没有填写哦","alert-error");
		return false;
	}else if(phonenum.length != '11'){
		$("input[name='phonenum']").focus();
		updateAlert("手机号格式不正确","alert-error");
		return false;
	}else if(!/^1[345678]\d{9}$/.test(phonenum)){
		$("input[name='phonenum']").focus();
		updateAlert("手机号格式不正确","alert-error");
		return false;
	}else if(!code || code == ""){
		$("#z-message-code").focus();
		updateAlert("验证码还没填写哦","alert-error");
		return false;
	}
	
	
	
    var remember = 1;
	if($("#sms-login .remember_login").hasClass('color929')){
		remember = 0;
        return false;
    }
    
	var data_url = even.attr('data-url');
	even.html("登录中...");
	even.attr("go",0);
	$.ajax({ 
		dataType:'json',
        url: data_url, 
        type:"post",
        data: {back_url:back_url,phonenum:phonenum,code:code,remember:remember,__ziwork_hash__:ziwork_hash,login_type:"sms"},
        success: function(obj){
        	
        	even.html("登录自客");
        	even.attr("go",1);
        	
           if(obj.status == 1){
        	   updateAlert("登录成功","alert-success");
        	   setInterval(function(){
        		   window.location.href = obj.info;
        	   }, 2000);
           }else {
        	   updateAlert(obj.info,"alert-error");
        	   
        	   /*if(obj.info == '请重新获取验证码'){
        		   var ref_img_data_url = $('#z-refresh-code').attr('data-url');
              	   $(".login-img-code img").attr('src',ref_img_data_url+'&t='+Math.random());
        	   }*/
        	  
        	   if(obj.token){
        		   $("meta[name='__ziwork_hash__']").attr('content',obj.token);
               }
               return false;
           }
        }
    });
	
});


//找回密码第一步
$("#retrievePwdFirst").click(function(){
	var phonenum = $("#phonenum").val();
	var code = $("#z-message-code").val();
	
	var even = $(this);
	
	var go = even.attr("go");
	if(go == "0"){
		updateAlert("正在提交中","alert-error");
		return false;
	}
	
	
	if(!phonenum){
		$("#phonenum").focus();
		updateAlert("手机号码还没有填写哦","alert-error");
		return false;
	}else if(phonenum.length != '11'){
		$("#phonenum").focus();
		updateAlert("手机号格式不正确","alert-error");
		return false;
	}else if(!/^1[345678]\d{9}$/.test(phonenum)){
		$("#phonenum").focus();
		updateAlert("手机号格式不正确","alert-error");
		return false;
	}else if(!code || code == ""){
		$("#z-message-code").focus();
		updateAlert("验证码还没填写哦","alert-error");
		return false;
	}
	
	
	var data_url = even.attr('data-url');
	even.html("提交中...");
	even.attr("go",0);
	$.ajax({ 
		dataType:'json',
        url: data_url, 
        type:"post",
        data: {phonenum:phonenum,code:code},
        success: function(obj){
        	
        	even.html("下一步");
        	even.attr("go",1);
        	
           if(obj.status == 1){
        	   updateAlert("提交成功","alert-success");
        	   setInterval(function(){
        		   window.location.href = obj.info;
        	   }, 2000);
           }else {
        	   updateAlert(obj.info,"alert-error");
               return false;
           }
        }
    });
	
	
});


//找回密码第二步
$("#retrievePwdSecond").click(function(){
	var first_pwd = $("#first-pwd").val();
	var second_pwd = $("#second-pwd").val();
	
	var even = $(this);
	var go = even.attr("go");
	if(go == "0"){
		updateAlert("正在提交中","alert-error");
		return false;
	}
	
	
	//密码必须由数字，字母，特殊字符中的两种以上组成--var passNum= !!passward.match(/(?=.*[a-z])(?=.*\d)(?=.*[#@!~%^&*])[a-z\d#@!~%^&*]{6,20}/i);
    var passNum= !!first_pwd.match(/^\S+$/gi);

    if(!first_pwd || first_pwd == ""){
		updateAlert("新密码必须填写~","alert-error");
		return false;
	}else if(passNum == false){
    	updateAlert("新密码不能有空格","alert-error");
        return false;
    }else if(first_pwd.length < 6){
    	updateAlert("新密码长度不能小于6位","alert-error");
        return false;
    }else if(second_pwd.length > 20){
    	updateAlert("新密码长度不能大于20位","alert-error");
        return false;
    }else if(first_pwd != second_pwd){
    	updateAlert("两次输入密码不一致，请重新输入","alert-error");
        return false;
    }
    
    var data_url = even.attr('data-url');
	even.html("提交中...");
	even.attr("go",0);
	$.ajax({ 
		dataType:'json',
        url: data_url, 
        type:"post",
        data: {first_pwd:first_pwd,second_pwd:second_pwd},
        success: function(obj){
        	
        	even.html("下一步");
        	even.attr("go",1);
        	
           if(obj.status == 1){
        	   updateAlert("提交成功","alert-success");
        	   setInterval(function(){
        		   window.location.href = obj.info;
        	   }, 2000);
           }else {
        	   updateAlert(obj.info,"alert-error");
               return false;
           }
        }
    });
	
});

//绑定手机号码
$("#bindPhonenum").click(function(){
	var phonenum = $("#phonenum").val();
	var pwd = $("#pwd").val();
	var code = $("#z-message-code").val();
	
	var even = $(this);
	var go = even.attr("go");
	if(go == "0"){
		updateAlert("正在提交中","alert-error");
		return false;
	}

	if(!phonenum){
		$("#phonenum").focus();
		updateAlert("手机号码还没有填写哦","alert-error");
		return false;
	}else if(phonenum.length != '11'){
		$("#phonenum").focus();
		updateAlert("手机号格式不正确","alert-error");
		return false;
	}else if(!/^1[345678]\d{9}$/.test(phonenum)){
		$("#phonenum").focus();
		updateAlert("手机号格式不正确","alert-error");
		return false;
	}
	
	if($("#pwd").length > 0){
		//密码必须由数字，字母，特殊字符中的两种以上组成--var passNum= !!passward.match(/(?=.*[a-z])(?=.*\d)(?=.*[#@!~%^&*])[a-z\d#@!~%^&*]{6,20}/i);
	    var passNum= !!pwd.match(/^\S+$/gi);
	    if(!pwd || pwd == ""){
			updateAlert("密码必须填写~","alert-error");
			return false;
		}else if(passNum == false){
	    	updateAlert("密码不能有空格","alert-error");
	        return false;
	    }else if(pwd.length < 6){
	    	updateAlert("密码长度不能小于6位","alert-error");
	        return false;
	    }else if(pwd.length > 20){
	    	updateAlert("密码长度不能大于20位","alert-error");
	        return false;
	    }
	}
	
	if(!code || code == ""){
		updateAlert("验证码还没填写哦","alert-error");
        return false;
	}
    
	var command = 1;
	if($("#scanning-code").hasClass('color929')){
		updateAlert("请勾选自客使用条约与协议","alert-error");
		command = 0;
        return false;
    }
	
	
	var is_company_from = $("#is_company_from").val();
	
	
    var data_url = even.attr('data-url');
	even.html("提交中...");
	even.attr("go",0);
	$.ajax({ 
		dataType:'json',
        url: data_url, 
        type:"post",
        data: {phonenum:phonenum,pwd:pwd,code:code,is_company_from:is_company_from,command:command},
        success: function(obj){
        	
        	even.html("完成手机绑定");
        	even.attr("go",1);
        	
           if(obj.status == 1){
        	   updateAlert("绑定成功","alert-success");
        	   setInterval(function(){
        		   window.location.href = obj.info;
        	   }, 2000);
           }else {
        	   updateAlert(obj.info,"alert-error");
               return false;
           }
        }
    });
});


